package org.jash.shop2201.utils

import android.content.Context
import android.content.SharedPreferences
import com.tencent.mmkv.MMKV

object StoreUtils {
    private lateinit var mmkv: MMKV
    fun initialize(context:Context) {
        MMKV.initialize(context)
        mmkv = MMKV.defaultMMKV()
    }
    fun save(key:String, value:String) {
        mmkv.encode(key, value)
    }
    fun save(key:String, value:Boolean) {
        mmkv.encode(key, value)
    }
    fun save(key:String, value:Int) {
        mmkv.encode(key, value)
    }
    fun save(key:String, value:Set<String>) {
        mmkv.encode(key, value)
    }
    fun getString(key: String, defaultValue:String) : String = mmkv.decodeString(key, defaultValue) ?: defaultValue
    fun getBoolean(key: String, defaultValue:Boolean) : Boolean = mmkv.decodeBool(key, defaultValue) ?: defaultValue
    fun getInt(key: String, defaultValue:Int) : Int = mmkv.decodeInt(key, defaultValue) ?: defaultValue
    fun getStringSet(key: String, defaultValue:Set<String>) : Set<String> = mmkv.decodeStringSet(key, defaultValue) ?: defaultValue
}